package com.laoluo.erp.struts.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.stereotype.Component;

import com.laoluo.erp.domain.User;
import com.laoluo.erp.service.UserService;
import com.laoluo.erp.util.PageListData;

@SuppressWarnings("serial")
@ParentPackage("struts-default")
@Namespace("/")
@Action("user")
public class UserAction extends BaseAction {
	
	@Resource(name="userServiceImpl")
	private UserService userService;
	
	public void getAll(){
		List<User> list = userService.findAll();
		resultSuccess("success",list,list.size());
	}
	
	public void insert(){}
	
	public void update() throws IOException{	
        User user = readJson(User.class);
        userService.update(user);
        resultSuccess("update success");
	}
	public void queryPage(){
		Map<String, String> map = new HashMap<String,String>();
		map.put("keyword", getRequest().getParameter("keyword"));
		int limit = Integer.parseInt(getRequest().getParameter("limit"));
		int start = Integer.parseInt(getRequest().getParameter("start"));
		int page = Integer.parseInt(getRequest().getParameter("page"));
		PageListData data = userService.queryPage(map,start,limit,page);
		resultSuccess("",data.getDataList(),data.getTotalcount());
	}
}
